/**
 * 创建者：luyiming
 * 该页面用于：
 * 创建时间： 2020-03-06 21:47:02
 */
import Table from "@/components/Table";
import Pagination from "@/components/Pagination"; // 分页
import ReportTable from "@/components/luyiming/ReportTable/index.vue";
import AbnormalTemplate from "@/template/abnormal.temp.vue";
import { reportDetial, entDetial, getDeclareNewRadsStatic, getDeclareNewRadsStaticDetail } from "@/api/RCIM/RCIM-addandstorage";
import {
	cloneDeep
} from "lodash";
import moment from "moment";
export default {
	name: 'RcimAddandstorageStatistics_view',
	components: {
		Table,
        Pagination,
        ReportTable,
		AbnormalTemplate,
	},
	// 数据
	data() {
		return {
			datePickType: {
				format: "yyyy-MM",
				precise: "month",
				longer: "30"
			},
			tableData: [],
			tableHead: [],
			tableHeadOne: [{
					id: 'enterprise',
					name: '企业',
					width: "",
					align: "center"
				},
				{
					id: 'addSourceTimeNum',
					name: '新增申报次数',
					width: "",
					align: "center"
				},
				{
					id: 'stroageTimeNum',
					name: '收贮申报次数',
					width: "",
					align: "center"
				},
				{
					id: "operate",
					name: "操作",
					width: "",
					align: "center"
				}
			],
			tableHeadTwo: [{
					id: 'declareTime',
					name: '申报时间',
					width: "",
					align: "center"
				},
				{
					id: 'addSourceNum',
					name: '新增源数',
					width: "",
					align: "center"
				},
				{
					id: 'stroageNum',
					name: '收贮源数',
					width: "",
					align: "center"
				},
				{
					id: "operate",
					name: "操作",
					width: "",
					align: "center"
				}
			],
			listLoading: false,
			total: 0,
			total1: 0,
			listQuery: {
				page: 1,
				limit: 10
			},
			listQuery1: {
				date: '',
				id: '',
			},
            tableLevel: 1,

			dialogFormVisible: false,
			timeParam: '',
			reportTable: [
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '企业名称',
						key: 'name',
						disable: true,
					}]
                },
				{
					col: [{
						fspan: 24,
						span: [24, 0],
						name: '放射源（单位/枚）',
						key: null,
					}]
				},
				{
					col: [{
						fspan: 12,
						span: [12, 12],
						name: '登记人：',
						key: 'registrant',
						disable: true,
					},{
						fspan: 12,
						span: [12, 12],
						name: '企业负责人：',
						key: 'chargePerson',
						disable: true,
					}]
				},
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '申报日期：',
						key: 'declareTime',
						formType: 'date-picker',
						formTypeC: 'option',
						options: []
					}]

				},
			],
			newSourceReport: [
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '新增源数',
						key: 'newSourceNum',
                        disable: true,
                        showAfter: true,
					}]

                },
			],
			stroageReport: [
				{
					col: [{
						fspan: 24,
						span: [6, 18],
						name: '收贮源数',
						key: 'stroageSourceNum',
						disable: true,
                        showAfter: true,
					}]

				},
			],
			newSourceForm:[],
			storageSourceForm:[],
			reportSourceTitle: "放射源新增申请表",
			reportStroageTitle: "放射源收贮申请表",
			isShowNewSourceReport: false,
			isReadOnly: false,
		}
	},
	// 监听
	watch: {

	},
	// Vue实例初始化完成
	created() {
        this.newSourceForm = cloneDeep(this.reportTable);
		this.newSourceForm.splice(1,0,...this.newSourceReport);
		this.storageSourceForm = cloneDeep(this.reportTable);
		this.storageSourceForm.splice(1,0,...this.stroageReport);
    },
	// Vue挂载完成
	mounted() {

	},
	// Vue实例销毁前
	beforeDestroy() {

	},
	// 挂载的方法
	methods: {
		/**
		 * 表格获取数据
		 */
		getList() {
			this.tableLevel = 1
			this.headAssign()
			this.listLoading = true
			// 接口调用
			getDeclareNewRadsStatic(this.listQuery).then(res => {
				this.listLoading = false
				this.total = res.data.total
				this.tableData = res.data.data
			}).catch(e => {
				this.listLoading = false
			})
		},
		getDetailList(row) {
			this.tableLevel = 2
			this.headAssign(true)
			// this.listLoading = true
			// 接口调用
			getDeclareNewRadsStaticDetail(this.listQuery1).then(res => {
				this.listLoading = false
				this.tableData = res.data.map(item => {
					item.entName = row.enterprise;
					return item;
				})
			})
		},
		/**
		 * 点击树调用函数
		 */
		treeHandle(param) {
			let {treeType,time} = param
			Object.assign(this.listQuery,{treeType,date: moment(time).format('YYYY-MM')}, {
				nodeId: param.id,
				nodeType: param.type
			})
			this.getList()
		},
		/**
		 * 表头赋值
		 */
		headAssign(num) {
			if (num) {
				this.tableHead = cloneDeep(this.tableHeadTwo)
			} else {
				this.tableHead = cloneDeep(this.tableHeadOne)
			}
		},
		/**
		 * 获取子级表格
		 */
		detailTable(row) {
			Object.assign(this.listQuery1, {
				id: row.id,
				date: this.listQuery.date,
			})
			this.getDetailList(row)
		},
		/**
		 * 返回上个表格
		 */
		showReturn() {
			this.getList()
        },
		/**
		 * 打开弹窗
		 */
		openDialog() {
			this.dialogFormVisible = true
        },
        entInfo(){
			return entDetial({}).then(res => {
				return res?.data?.entData ?? {}
			})
        },
        async handleFind(row){
            this.openDialog();
            this.isShowNewSourceReport = row.type === 1;
            this.isReadOnly = true;
            const detialData = await reportDetial({
                id: row.id,
                type: row.type,
            }).then(res => {
                const result = res.data.detialData;
                result.countryCode.split(',').forEach((itemV, inde) => {
                    result['code__' + inde] = itemV;
                })
                delete result.countryCode;
                return result
            })
			if(this.isShowNewSourceReport){
				console.log(this.$refs.reportSource, this.$refs.reportSource.setDefaultValue)
				this.$refs.reportSource.setDefaultValue(Object.assign({name: row.entName}, detialData))
			}else{
				this.$refs.reportDevice.setDefaultValue(Object.assign({name: row.entName}, detialData))
			}
        },
	},
}
